/* Copyright (C) 2010 Luca Piccinelli
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* 
 * File:   gestface_exceptions.h
 * Author: picci
 *
 * Created on February 14, 2011, 8:21 PM
 */

#ifndef GESTFACE_EXCEPTIONS_H
#define	GESTFACE_EXCEPTIONS_H

#include <exception>

namespace NAMESPACE{
// Exception class
// Inline declaration
class gestface_exception : public std::exception{

protected:
    std::string what_msg;

public:
    virtual ~gestface_exception() throw(){}
    gestface_exception(const std::string& _what_msg) : std::exception() { what_msg = _what_msg; }

    virtual const char* what() const throw(){
        return what_msg.c_str();
    }
};

class gestface_unexpected_exception : public gestface_exception{
public:
    virtual ~gestface_unexpected_exception() throw(){}
    gestface_unexpected_exception(const std::string& _what_msg) : gestface_exception(_what_msg) {}
};

// ****** Unexpected exceptions handler ****************************************
class UnexpectedExHandler{
private:
    std::unexpected_handler old_ex_handler;
    UnexpectedExHandler();
    UnexpectedExHandler(const UnexpectedExHandler& h);
    UnexpectedExHandler& operator=(const UnexpectedExHandler& h);
public:
    UnexpectedExHandler(std::unexpected_handler new_ex_handler){ old_ex_handler = std::set_unexpected(new_ex_handler); }
    ~UnexpectedExHandler(){std::set_unexpected(old_ex_handler);}
};

inline void throw_unexpected() throw(gestface_unexpected_exception){
    throw gestface_unexpected_exception("unexpected exception thrown");
}
// -----------------------------------------------------------------------------

}

#endif	/* GESTFACE_EXCEPTIONS_H */

